package com.powerbank.ordercenter.mq.consumer;

import com.powerbank.common.event.payment.PaymentSuccessEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

/**
 * 支付成功事件消费者
 */
@Slf4j
@Service
@RequiredArgsConstructor
@RocketMQMessageListener(
    topic = "payment-success-topic",
    consumerGroup = "order-center-payment-consumer-group"
)
public class PaymentSuccessEventConsumer implements RocketMQListener<PaymentSuccessEvent> {

    @Override
    public void onMessage(PaymentSuccessEvent event) {
        try {
            log.info("接收到支付成功事件: orderId={}, paymentId={}", event.getOrderId(), event.getPaymentId());
            
            // 处理支付成功逻辑
            // 可以在这里更新订单状态、发送通知等
            
        } catch (Exception e) {
            log.error("处理支付成功事件失败: {}", event, e);
            throw e; // 重新抛出异常，触发重试
        }
    }
}